Skip to content

ML-DSA AArch64: prepared keys for many signatures and verifications - #4375

Merged
reaperhulk merged 2 commits into
mainfrom
claude/wonderful-planck-ihi993-prepared
Nov 6, 2026
Merged

reaperhulk merged 2 commits into
mainfrom
claude/wonderful-planck-ihi993-prepared

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Stacked on #4366 (the specification). This takes over #3819, with an explicit prepared-key API in place of its automatic cache.

API

let pk = VerifyingKey44::from_bytes(&bytes).prepare();   // decode + NTT once
pk.verify(msg, ctx, &sig)?;                              // for every message after

let sk = SigningKey44::from_seed(&seed)?.prepare();
let sig = sk.sign(msg, ctx)?;                            // also sign_deterministic
  • PreparedSigningKey{44,65,87} and PreparedVerifyingKey{44,65,87} are for a key that signs or verifies a stream of messages.
    • prepare(self) consumes the key; signing_key() / verifying_key() return it.
    • The prepared bytes are stored inline, 64-byte aligned. There's no allocation, no lazy or shared mutable state, and no publication protocol.
    • They're immutable, so threads can share one. A prepared private key wipes its prepared bytes on drop, and its key wipes itself as before.
  • Only callers who keep a key pay for preparing it, plus the extra size on AArch64: 5,408 / 8,096 / 10,784 bytes for a public key and 14,848 / 21,440 / 28,448 bytes for a private key (44 / 65 / 87). The ordinary key types and their methods are unchanged.
  • On AArch64 the prepared keys call vg_mldsa*_sign_message_prepared and vg_mldsa*_verify_message_prepared, with the scalar and _sha3 variants chosen exhaustively by Backend. On every other architecture they call the ordinary functions, so the API is the same everywhere.

Verified code (AArch64)

The implementation and proofs are #3819's, rebased onto main (417 commits newer):

  • Registered entries. The new registration file Artifacts/MlDsaPreparedKey/AArch64.lean registers vg_mldsa*_prepare_{signing,verifying}_key. The Keccak generic files register the ordinary entries and vg_mldsa*_{sign,verify}_message_prepared.
  • Shared kernels. The ordinary and prepared entries share one signing and one verification kernel per parameter set and Keccak backend: vg_mldsa*_sign_with_cache and vg_mldsa*_verify_with_cache, which take an optional slice holding the key's polynomials.
  • Internal functions. Per ML-DSA: no specs for its internal functions #3914, the kernels and the μ entries with a prepared key (vg_mldsa*_{sign,verify}_prepared) are internal functions (crates/verified-garbage-asm-aarch64/src/internal/). Their contracts are untrusted, in Proof/MlDsa/PreparedKeyContract.lean. It also proves polyStored_iff, that the spec's PolyStored is PolyIs.
  • Rebase repairs.
    • Six lemmas main deleted as dead code are restated in the modules that use them: PostB.refl, PPostB.mono, selectedPairedSignLoop_ok, selectedPairedSignLoop_tr, finish_rootPair, and three verify-call lemmas, now taken from Optimized.CachedVerify.
    • Uses of other removed names (KeyGen.prims, Sig.u64Bufs) follow main.
    • Nothing in TCB/, Spec/ or Proof/Framework/ changes.

Performance (AArch64)

Benchmarks run, scoped to the ML-DSA sign/verify groups on ubuntu-26.04-arm, compared against main d3d83849a. It's one short interleaved pass per side (25 samples, about 0.3 s each), so the numbers are indicative.

Prepared vs ordinary on this branch, detected features (SHA3):

Ordinary Prepared Faster
44 sign (deterministic) 102.36 µs 95.87 µs 6.3%
65 sign (deterministic) 163.14 µs 151.46 µs 7.2%
87 sign (deterministic) 199.71 µs 187.21 µs 6.3%
44 verify 35.31 µs 33.29 µs 5.7%
65 verify 57.33 µs 54.28 µs 5.3%
87 verify 97.01 µs 92.87 µs 4.3%
  • No regression to the ordinary methods. Against main, deterministic signing, verification and the μ methods are within 0.4% in all three configurations (detected, sha3, none). Hedged sign moves ±4% either way between runs, because its randomness changes how many times the rejection loop runs.
  • Verifying-key preparation (mldsa*_prepare/verifying) costs 5.1 / 7.6 / 10.2 µs, so it pays for itself after about 2.5 verifications.
  • Signing-key preparation isn't measured separately. mldsa*_prepare/signing times key generation plus preparation together: 54 / 88 / 137 µs.
  • With VG_CPU_FEATURES=none, prepared operations are about 4–6% faster.

Validation

  • Lean: every new and edited module builds, and the full Emit.lean runs clean. Its standard-axiom, compiled-code and spec-origin audits pass, and it changes only crates/verified-garbage-asm-aarch64.

  • check_lean_public_imports.py --base origin/main passes on the 30 edited modules. All the Static checks steps pass locally, including check_variants.py, check_mcdt.py and algorithms_table.py --check.

  • Rust, x86-64 native: the ML-DSA tests pass, cargo fmt and cargo clippy --all-targets -D warnings are clean, and the benchmarks build.

  • Rust, AArch64 cross-compiled under qemu-aarch64 -cpu max: the ML-DSA integration tests pass with detected features (the SHA3 variants) and with VG_CPU_FEATURES=none, and cargo clippy --target aarch64-unknown-linux-gnu --all-targets -D warnings is clean.

  • Tests use published vectors. Each Wycheproof key group is signed and verified with one prepared key, the streaming pattern:

    • deterministic signatures equal the vectors';
    • every valid vector verifies, and every invalid one is refused;
    • hedged signatures verify;
    • contexts over 255 bytes are refused.

    Unit-level checks cover the accessors, Debug, and a prepared key agreeing with its unprepared key.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWy42drMfWKyQXeWwK8

@reaperhulk
reaperhulk marked this pull request as ready for review November 6, 2026 21:28
@reaperhulk
reaperhulk added this pull request to stack #4378 November 6, 2026 21:31
@reaperhulk
reaperhulk enabled stacked auto-merge November 6, 2026 21:33
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

This pull request has conflicts with claude/wonderful-planck-ihi993, found after 35f5628 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

@reaperhulk
reaperhulk force-pushed the claude/wonderful-planck-ihi993-prepared branch from d2e99b5 to 6285cc9 Compare November 6, 2026 21:57
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to invalid changes in the merge commit Nov 6, 2026
Base automatically changed from claude/wonderful-planck-ihi993 to main November 6, 2026 22:24
@reaperhulk
reaperhulk force-pushed the claude/wonderful-planck-ihi993-prepared branch 2 times, most recently from 0f1705d to 806abd0 Compare November 6, 2026 22:31
@reaperhulk
reaperhulk enabled stacked auto-merge November 6, 2026 22:31
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

This pull request has conflicts with main, found after ab17026 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

SigningKey{44,65,87}::prepare and VerifyingKey{44,65,87}::prepare give a
PreparedSigningKey / PreparedVerifyingKey: the key, with its polynomials
decoded and transformed once (vg_mldsa*_prepare_signing_key,
vg_mldsa*_prepare_verifying_key), for a key that signs or verifies a
stream of messages. Its sign, sign_deterministic and verify call
vg_mldsa*_sign_message_prepared and vg_mldsa*_verify_message_prepared on
AArch64, and the ordinary functions elsewhere. The prepared bytes are
inline (no allocation), immutable, and wiped on drop for a private key.

The implementation and proofs are those of #3819,
rebased onto main:

* The ordinary and prepared entries share one signing and one
  verification kernel per parameter set and Keccak backend
  (vg_mldsa*_sign_with_cache, vg_mldsa*_verify_with_cache), which take an
  optional slice of the key's polynomials. They and the entries on mu with
  a prepared key (vg_mldsa*_sign_prepared, vg_mldsa*_verify_prepared) are
  internal functions now, their contracts untrusted in
  Proof/MlDsa/PreparedKeyContract.lean, with polyStored_iff relating the
  spec's PolyStored to PolyIs.
* Lemmas main deleted as dead code (PostB.refl, PPostB.mono,
  selectedPairedSignLoop_ok/_tr, finish_rootPair) are restated in the
  modules that use them, and the uses of removed names (KeyGen.prims,
  Sig.u64Bufs, the verify_message call lemmas) follow main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWy42drMfWKyQXeWwK8
…Regions; regenerate

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWy42drMfWKyQXeWwK8
@reaperhulk
reaperhulk force-pushed the claude/wonderful-planck-ihi993-prepared branch from 806abd0 to a4b74f2 Compare November 6, 2026 22:39
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 9ff6f96 Nov 6, 2026
35 checks passed
@reaperhulk
reaperhulk deleted the claude/wonderful-planck-ihi993-prepared branch November 6, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants